package code.jzh.monitor.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * 配置文件工具类
 * @author shuyingwu
 *
 */
public class PropertiesUtil {
	private static final String REG = "agentconfig.properties";
	
	public static Properties props = new Properties();
	
	static{
		File jarPath=new File(PropertiesUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath());
		String configFilePath = jarPath.getParentFile().getParentFile().getAbsolutePath()+"/classes/"+REG;
		FileInputStream in = null;
		try {
			in = new FileInputStream(configFilePath);
			props.load(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取agent代理 扫描 类路径规则
	 * 
	 * @return
	 */
	public static List<String> getRegList(String key) {
		List<String> methodList = new ArrayList<String>(10);
		if(props==null || props.size()==0){
			return methodList;
		}

        String mas = (String)props.get(key);
        if (mas != null && mas.trim().indexOf(",") > -1) {
			String[] strs = mas.split(",");
			for (String s : strs) {
				if (s.trim().length()>0) {
					methodList.add(s.trim());
				}
			}
		}
		return methodList;
		
		/*
		
		List<String> methodList = new ArrayList<String>(10);
		Properties prop = new Properties();// 属性集合对象
		try {
			prop.load(ClassLoader.getSystemResourceAsStream(REG));// 将属性文件流装载到Properties对象中
		} catch (IOException e) {
			e.printStackTrace();
		}
		String mas = prop.getProperty(key);
		if (mas != null && mas.trim().indexOf(",") > -1) {
			String[] strs = mas.split(",");
			for (String s : strs) {
				if (s.trim().length()>0) {
					methodList.add(s.trim());
				}
			}
		}
		return methodList;*/
	}

}
